package com.imodia.checkoo.lucence.search;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;

import com.hsq.commons.util.beans.BeanUtils;

public class LuceneSearchUtil<T> {
	
	private static Log log = LogFactory.getLog(LuceneSearchUtil.class);

	@SuppressWarnings("unchecked")
	public static <T> T getObj(Document document, Class<T> cls){		
		T t =   BeanUtils.newInstance(cls);
		List<Field> list2 = document.getFields();
		for(int k=0;k<list2.size();k++){
			Field field = list2.get(k);
			if(!field.name().equals("class")){
				 //log.debug(field.name()+"___"+document.get(field.name()));
				 BeanUtils.set(t, field.name(), document.get(field.name()));
			}
		}
		return t;
	}

}
